/**
 * @date 9:19:37 AM
 * EducationStudentController.java
 * Administrator
 * TODO
 */
package com.qs.education.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.beans.EducationStudentBean;
import com.qs.education.bean.beans.EducationStudentResponse;
import com.qs.education.bean.entity.EducationStudent;
import com.qs.education.service.IStudentAPPService;

/**
 * @class EducationStudentController	
 * @author Warren
 * @description
 * @date Nov 1, 2018 
 */
@RestController
public class EducationStudentController {
	
	@Autowired
	private IStudentAPPService studentAPPService;
	private final Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * @author Warren
	 * @param id
	 * @return Map<String,Object>
	 * @description 
	 * @date Nov 20, 2018
	 */
	@RequestMapping("/student/getStudentById")
	public EducationStudentResponse getStudentById(Long id){
		log.info("APP端逻辑");
		EducationStudentResponse educationStudent = studentAPPService.getEducationStudent(id);
		return educationStudent;
	}
	
	/**
	 * @author Warren
	 * @param mobile
	 * @return Map<String,Object>
	 * @description 根据手机号查询是否已注册
	 * @date Nov 7, 2018
	 */
	@RequestMapping("/student/mobileIsRepeat")
	public Map<String, Object> mobileIsRepeat(String mobile){
		log.info("APP端逻辑");
		ResponseBean responseBean = studentAPPService.mobileIsRepeat(mobile);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseBean", responseBean);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param student 
	 * @return Map<String,Object>
	 * @description
	 * @date Nov 5, 2018
	 */
	@RequestMapping("/student/register")
	public Map<String, Object> register(@RequestBody EducationStudentBean student){
		log.info("api");
		ResponseBean responseBean = studentAPPService.register(student);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseBean", responseBean);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param mobile
	 * @param password
	 * @return Map<String,Object>
	 * @description 用户登录，成功则返回token。
	 * @date Nov 6, 2018
	 */
	@RequestMapping("/student/login")
	public Map<String, Object> login(String mobile,String password) {
		log.info("api");
		EducationStudentResponse educationStudent = studentAPPService.login(mobile, password);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("educationStudent", educationStudent);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param mobile
	 * @return Map<String,Object>
	 * @description 学生退出
	 * @date Nov 6, 2018
	 */
	@RequestMapping("/student/exit")
	public Map<String, Object> login(String mobile) {
		log.info("api");
		ResponseBean responseBean = studentAPPService.exit(mobile);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseBean", responseBean);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param mobile
	 * @return Map<String,Object>
	 * @description 找回密码
	 * @date Nov 6, 2018
	 */
	@RequestMapping("/student/resetPwd")
	public Map<String, Object> resetPwd(String mobile,String password) {
		log.info("api");
		ResponseBean responseBean = studentAPPService.resetPwd(mobile, password);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseBean", responseBean);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param educationStduent
	 * @return Map<String,Object>
	 * @description 修改学生信息
	 * @date Nov 14, 2018
	 */
	@RequestMapping("/student/updateStudentInfo")
	public Map<String, Object> updateStudentInfo(EducationStudent educationStduent,MultipartFile file,String schoolId,String gradeId,String classId,HttpServletRequest request){
		ResponseBean responseBean = studentAPPService.updateStudentInfo(educationStduent, file, schoolId, gradeId, classId,request);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("responseBean", responseBean);
		return map;
	}
	
	/**
	 * @author Warren
	 * @param mobile 手机号
	 * @param oldPassword 原密码
	 * @param newPassword 新密码
	 * @return ResponseBean
	 * @description 修改密码
	 * @date Nov 20, 2018
	 */
	@RequestMapping("/student/changePwd")
	public ResponseBean changePwd(String mobile,String oldPassword,String newPassword){
		ResponseBean responseBean = studentAPPService.changePwd(mobile, oldPassword, newPassword);
		return responseBean;
	}
	
	/**
	 * @author Warren
	 * @param groupId 
	 * @param studentId
	 * @return ResponseBean
	 * @description 学生主动退出班群
	 * @date Nov 20, 2018
	 */
	@RequestMapping("/student/exitGroup")
	public ResponseBean exitGroup(Long groupId,Long studentId){
		ResponseBean responseBean = studentAPPService.exitGroup(groupId, studentId);
		return responseBean;
	}
}
